package com.ship.contract.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ship.contract.bean.ConTemplateClause;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author tangshixuan
 * @date 2023-9-13
 */
public interface ConTemplateClauseMapper extends BaseMapper<ConTemplateClause> {

    /**
     * 根据合同模板ID查询条款类别
     * @param templateId
     * @return
     */
    @Select("select clause_type as clauseType,count(*) count from con_template_clause where template_id = #{templateId} group by clause_type")
    List<Map<String, Object>> clauseTypesByTemplateId(@Param("templateId") Long templateId);

    /**
     * 删除模板时同时删除相关条款
     * @param id
     */
    @Delete("DELETE FROM con_template_clause WHERE template_id = #{id}")
    void removeByTemplateid(Long id);
}
